#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char* argv[]) {
    int fd_source = open(argv[1], O_RDONLY);
    if(fd_source == -1) {
        printf("open source error!\n");
        return 0;
    }
    int fd_target = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0777);
    if(fd_target == -1) {
        printf("open target error!\n");
        return 0;
    }
    char buffer[1024];
    int s_status;
    while(s_status = read(fd_source, buffer, 1024)) {
        if(s_status == 1024) write(fd_target, buffer, 1024);
        else {
            buffer[s_status] = '\0';
            write(fd_target, buffer, s_status);
        }
    }
    close(fd_source);
    close(fd_target);
    return 0;
}
